﻿using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using CardGenerator.ViewModel;
using Microsoft.Win32;

namespace CardGenerator.UI.Pages;

public partial class TemplateManagerPage : UserControl
{
    public TemplateManagerPage()
    {
        InitializeComponent();
    }

    protected override void OnInitialized(EventArgs e)
    {
        base.OnInitialized(e);
        (this.DataContext as TemplateManagerViewModel).Initialize(this);
    }

    public String? ShowTemplateSelectionDialog()
    {
        var dialog = new OpenFileDialog
        {
            Filter = "Template file|*.tp",
            Title = "Please select template file",
            Multiselect = false,
        };

        if (dialog.ShowDialog() ?? false)
        {
            return dialog.FileName;
        }

        return null;
    }

    public String? ShowTemplateSaveDialog(String? templateName)
    {
        var dialog = new SaveFileDialog
        {
            Filter = "Template file|*.tp",
            FileName = $"{templateName}.tp"
        };
        if (dialog.ShowDialog() ?? false)
        {
            return dialog.FileName;
        }
        return null;
    }

    public void ShowMessageBox(String message)
    {
        MessageBox.Show(message);
    }
}